package com.wangjialu.learner.payment.controller;

import com.wangjialu.learner.payment.entities.Payment;
import com.wangjialu.learner.payment.service.PaymentService;
import com.wangjialu.learner.payment.vo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p></p>
 *
 * @author WangJialu
 * @since 2021/6/22 4:44
 */
@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @PostMapping("/payment/insert")
    public CommonResult insert(@RequestBody Payment payment) {
        int result = paymentService.insert(payment);
        log.debug("********插入结果：" + result);
        if (result > 0) {
            return new CommonResult(200, "success", result);
        }
        return new CommonResult(444, "插入数据失败");
    }

    @GetMapping("/payment/getById/{id}")
    public CommonResult getById(@PathVariable("id")Long id) {
        Payment payment = paymentService.queryById(id);
        log.debug("********查询结果：" + payment);
        if (null != payment) {
            return new CommonResult(200, "success", payment);
        }
        return new CommonResult(444, "没有对应记录");
    }
}
